package com.ssy.lingxi.member.merchant.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Objects;

/**
 * 会员资质证明（文件）
 * @author 万宁
 * @version 2.0.0
 * @date 2021-05-20
 */
@Entity
@Table(schema = "public", name = "ms_mc_member_quality", indexes = {@Index(name="ms_mc_member_quality_relation_id_idx", columnList = "relation_id")})
public class MemberQualityDO implements Serializable {
    private static final long serialVersionUID = 3073756086717917900L;

    /**
     * 主键id
     */
    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="member_quality_seq")
    @SequenceGenerator(sequenceName="ms_mc_member_quality_seq", name="member_quality_seq",allocationSize = 1)
    private Long id;

    /**
     * 多对一双向关联会员关系
     */
    @JsonBackReference
    @ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinColumn(name = "relation_id")
    private MemberRelationDO relation;

    /**
     * 文件Url
     */
    @Column(columnDefinition = "varchar(400)")
    private String url;

    /**
     * 文件名称
     */
    @Column(columnDefinition = "varchar(255)")
    private String name;

    /**
     * 有效日期
     */
    @Column(columnDefinition = "timestamp")
    private LocalDateTime expireTime;

    /**
     * 是否长期有效，0-否，1-是
     */
    @Column
    private Integer permanent;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public MemberRelationDO getRelation() {
        return relation;
    }

    public void setRelation(MemberRelationDO relation) {
        this.relation = relation;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public LocalDateTime getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(LocalDateTime expireTime) {
        this.expireTime = expireTime;
    }

    public Integer getPermanent() {
        return permanent;
    }

    public void setPermanent(Integer permanent) {
        this.permanent = permanent;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        MemberQualityDO that = (MemberQualityDO) o;
        return id.equals(that.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
